<?php


namespace App\Services\Formatter;


use App\Model\MeetingTemplate;
use Carbon\Carbon;
use Hyperf\Utils\Codec\Json;

class MeetingTplFormatter
{
    public function stdoutFormatter(MeetingTemplate $tpl): array
    {
        return [
            'tplId' => $tpl->id,
            'userId' => $tpl->user_id,
            'title' => $tpl->title,
            'content' => $tpl->content,
            'userLimit' =>$tpl->user_limit,
            'signRules' => Json::decode($tpl->sign_rules),
            'signFields' => $tpl->sign_fields ? Json::decode($tpl->sign_fields) : [],
            'signType' => $tpl->sign_type,
            'allowLaterSign' => $tpl->allow_later_sign,
            'status' => $tpl->status,
            'createTime' => Carbon::parse($tpl->created_at)->format('Y-m-d H:i:s'),
            'updateTime' => Carbon::parse($tpl->updated_at)->format('Y-m-d H:i:s'),
        ];
    }

    public function formatList($models)
    {
        $result = [];
        foreach ($models as $model) {
            /* @var $model MeetingTemplate */
            $result[] = $this->stdoutFormatter($model);
        }
        return $result;
    }
}
